


package jnpf.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.service.BillRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.base.UserInfo;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.exception.DataException;
import org.springframework.transaction.annotation.Transactional;
import jnpf.base.entity.ProvinceEntity;
import jnpf.model.zxgl_zhidingdubanren.*;
import jnpf.model.zxgl_zhidingdubanren.ZXGL_ZhiDingDuBanRenPagination;
import jnpf.entity.*;
import jnpf.base.service.ProvinceService;
import jnpf.util.*;
import jnpf.base.util.*;
import jnpf.base.vo.ListVO;
import jnpf.util.context.SpringContext;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import jnpf.generater.util.GeneraterSwapUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jnpf.entity.ZXGL_ZhiDingDuBanRenEntity;
import jnpf.service.ZXGL_ZhiDingDuBanRenService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

import jnpf.file.FileApi;
import jnpf.emnus.FileTypeEnum;
import jnpf.model.upload.UploadFileModel;

import java.io.ByteArrayOutputStream;

import jnpf.provider.file.FileUploadProvider;
import org.apache.dubbo.config.annotation.DubboReference;

/**
 * ZXGL_ZhiDingDuBanRen
 *
 * @版本： V2.0
 * @版权： 河北交投智能交通技术有限责任公司
 * @作者： 数字交投项目组
 * @日期： 2025-03-08
 */
@Slf4j
@RestController
@Api(tags = "ZXGL_ZhiDingDuBanRen", value = "zxgl")
@RequestMapping("/ZXGL_ZhiDingDuBanRen")
public class ZXGL_ZhiDingDuBanRenController {


    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;
    @Autowired
    private UserProvider userProvider;

    @Autowired
    private ZXGL_ZhiDingDuBanRenService zXGL_ZhiDingDuBanRenService;


    /**
     * 列表
     *
     * @param zXGL_ZhiDingDuBanRenPagination
     * @return
     */
    @PostMapping("/getList")
    public ActionResult list(@RequestBody ZXGL_ZhiDingDuBanRenPagination zXGL_ZhiDingDuBanRenPagination) throws IOException {
        List<ZXGL_ZhiDingDuBanRenEntity> list = zXGL_ZhiDingDuBanRenService.getList(zXGL_ZhiDingDuBanRenPagination);
        //处理id字段转名称，若无需转或者为空可删除
        for (ZXGL_ZhiDingDuBanRenEntity entity : list) {
            entity.setCjr(generaterSwapUtil.userSelectValues(entity.getCjr()));
            entity.setCjrbm(generaterSwapUtil.comSelectValues(entity.getCjrbm()));
            entity.setDbr(generaterSwapUtil.userSelectValues(entity.getDbr()));
        }
        List<ZXGL_ZhiDingDuBanRenListVO> listVO = JsonUtil.getJsonToList(list, ZXGL_ZhiDingDuBanRenListVO.class);
        for (ZXGL_ZhiDingDuBanRenListVO zXGL_ZhiDingDuBanRenVO : listVO) {
        }


        PageListVO vo = new PageListVO();
        vo.setList(listVO);
        PaginationVO page = JsonUtil.getJsonToBean(zXGL_ZhiDingDuBanRenPagination, PaginationVO.class);
        vo.setPagination(page);
        return ActionResult.success(vo);
    }


    /**
     * 创建
     *
     * @param zXGL_ZhiDingDuBanRenCrForm
     * @return
     */
    @PostMapping
    @Transactional
    public ActionResult create(@RequestBody @Valid ZXGL_ZhiDingDuBanRenCrForm zXGL_ZhiDingDuBanRenCrForm) throws DataException {
        String mainId = RandomUtil.uuId();
        UserInfo userInfo = userProvider.get();
        ZXGL_ZhiDingDuBanRenEntity entity = JsonUtil.getJsonToBean(zXGL_ZhiDingDuBanRenCrForm, ZXGL_ZhiDingDuBanRenEntity.class);
        entity.setId(mainId);
        entity.setCreatorTime(new Date());
        zXGL_ZhiDingDuBanRenService.save(entity);


        return ActionResult.success("创建成功");
    }


    /**
     * 信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ActionResult<ZXGL_ZhiDingDuBanRenInfoVO> info(@PathVariable("id") String id) {
        ZXGL_ZhiDingDuBanRenEntity entity = zXGL_ZhiDingDuBanRenService.getInfo(id);
        ZXGL_ZhiDingDuBanRenInfoVO vo = JsonUtil.getJsonToBean(entity, ZXGL_ZhiDingDuBanRenInfoVO.class);

        //子表
        //副表
        return ActionResult.success(vo);
    }

    /**
     * 表单信息(详情页)
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public ActionResult<ZXGL_ZhiDingDuBanRenInfoVO> detailInfo(@PathVariable("id") String id) {
        ZXGL_ZhiDingDuBanRenEntity entity = zXGL_ZhiDingDuBanRenService.getInfo(id);
        ZXGL_ZhiDingDuBanRenInfoVO vo = JsonUtil.getJsonToBean(entity, ZXGL_ZhiDingDuBanRenInfoVO.class);
        vo.setCjr(generaterSwapUtil.userSelectValues(vo.getCjr()));
        vo.setCjrbm(generaterSwapUtil.comSelectValues(vo.getCjrbm()));
        vo.setDbr(generaterSwapUtil.userSelectValues(vo.getDbr()));

        //子表数据转换

        //附表数据转换
        return ActionResult.success(vo);
    }


    /**
     * 更新
     *
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    @Transactional
    public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ZXGL_ZhiDingDuBanRenUpForm zXGL_ZhiDingDuBanRenUpForm) throws DataException {
        UserInfo userInfo = userProvider.get();
        ZXGL_ZhiDingDuBanRenEntity entity = zXGL_ZhiDingDuBanRenService.getInfo(id);
        if (entity != null) {
            ZXGL_ZhiDingDuBanRenEntity subentity = JsonUtil.getJsonToBean(zXGL_ZhiDingDuBanRenUpForm, ZXGL_ZhiDingDuBanRenEntity.class);
            zXGL_ZhiDingDuBanRenService.update(id, subentity);
            return ActionResult.success("更新成功");
        } else {
            return ActionResult.fail("更新失败，数据不存在");
        }
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id) {
        ZXGL_ZhiDingDuBanRenEntity entity = zXGL_ZhiDingDuBanRenService.getInfo(id);
        if (entity != null) {
            zXGL_ZhiDingDuBanRenService.delete(entity);

        }
        return ActionResult.success("删除成功");
    }


}
